/*
 * BonPlanBean.java
 *
 * Created on 11 janvier 2008, 04:32
 */
package com.reimscopie.beans.entities ;

import java.util.* ;

import javax.persistence.* ;

import com.reimscopie.* ;


/**
 * This is the entity bean for a bon plan.
 */
@Entity
@NamedQuery(
  name  = "all-bon-plans",
  query = "SELECT o FROM BonPlanBean o"
)
public class BonPlanBean extends ValueBean<BonPlan> {
  
  // the product
  private ProductBean product ;
  
  // end date
  private Date endDate ;
  
  // price factor
  private int factor ;
  
  
  /**
   * Create a new instance of <code>BonPlanBean</code> (default
   * constructor).
   */
  public BonPlanBean() {
    
  }
  
  
  /**
   * Create a new instance of <code>BonPlanBean</code> with all attributes.
   *
   * @param bonPlan The valued bon plan.
   * @param product The product bean.
   */
  public BonPlanBean(BonPlan bonPlan,ProductBean product) {
    
    if (bonPlan.hasId())
      throw new IllegalArgumentException("bon-plan has an image") ;
    
    this.product = product ;
    this.endDate = bonPlan.getEndDate() ;
    this.factor  = bonPlan.getFactor() ;
    
  }
  
  
  /**
   * Return the product of this bon plan.
   *
   * @return The product.
   */
  @OneToOne
  public ProductBean getProduct() {
    return product ;
  }
  
  
  /**
   * Set the product of this bon plan.
   *
   * @param product The new product.
   */
  public void setProduct(ProductBean product) {
    this.product = product ;
  }
  
  
  /**
   * Return the end date of this bon plan.
   *
   * @return The end date.
   */
  public Date getEndDate() {
    return endDate ;
  }
  
  
  /**
   * Set the end date of this bon plan.
   *
   * @param end The new end date./
   */
  public void setEndDate(Date end) {
    this.endDate = endDate ;
  }
  
  
  /**
   * Return the price factor of this bon plan.
   *
   * @return The price factor.
   */
  public int getFactor() {
    return factor ;
  }
  
  
  /**
   * Set the proce factor of this bon plan.
   *
   * @param factor The new price factor.
   */
  public void setFactor(int factor) {
    this.factor = factor ;
  }
  
  
  /**
   * Transform this entity bean into the associated value.
   * 
   * @return A new value instance.
   */
  @Override
  public BonPlan toValue() {
    
    return new BonPlan(
        getId(),
        getProduct().toProduct(),
        getEndDate(),
        getFactor()
    ) ;
    
  }
  
}
